<?php if (isset($add)) echo "<h2>Thêm Phòng</h2>"; else echo "<h2>Thay đổi thông tin Phòng</h2>";?>
<form name="edit_room_for_hotel" action="?act=createOrModifyRoomForHotel&room_id=<?php if (isset($room_id)) echo $room_id
 ?>&hotel_id=<?php echo $hotel_id ?>" method="POST" onsubmit="return validate_values()" enctype="multipart/form-data">
	<div class='row_field'>
    	<div class='label'>
			<label for="room_name">Tên Phòng(*):</label>
        </div>
        <div class='field'>
			<input type="text" class='inputbox' id="room_name" name="room_name" value="<?php if (isset($room)) echo $room->getname()?>">
        </div>
	</div>
	
	<div class='row_field'>
    	<div class='label'>
			<label for="price">Giá Phòng(*):</label>
        </div>
        <div class='field'>
			<input type="number" class='inputbox' id="price" name="price" value="<?php if (isset($room)) echo $room->getprice()?>">
			<?php $currencies = get_currency_list() ?>
			<div class='field'>
			<select id="currency" name="currency" class='inputbox'>
				<?php foreach ($currencies as $currency) {?>
				<option value="<?php echo $currency['id'] ?>" <?php 
					if (isset($room_id) && $currency['id'] == $room->getcurrency())
						echo 'selected="selected"';
					elseif (isset($add) && $currency['currency_code'] == 'VND')
						echo 'selected="selected"' 
					?>><?php echo $currency['currency_code'] ?></option>
				<?php } ?>
			</select>
        </div>
	</div>
	
	<div class='row_field'>
    	<div class='label'>
			<label for="promotion">Khuyến Mãi:</label>
        </div>
        <div class='field'>
			<input type="text" class='inputbox' id="promotion" name="promotion" value="<?php if (isset($room)) echo $room->getpromotion()?>">%
        </div>
	</div>
	
	<div class='row_field'>
    	<div class='label'>
			<label for="description">Miêu tả Phòng:</label>
        </div>
        <div style='clear:both'></div>
    </div>
    <div class='row_field'>
		<?php
		include("../fckeditor.php");
		$sBasePath = $_SERVER['PHP_SELF'] ;
		$sBasePath = substr( $sBasePath, 0, strpos( $sBasePath, "admin" ) ) ;
		
		$oFCKeditor = new FCKeditor('description') ;
		$oFCKeditor->BasePath	= $sBasePath ;
		$oFCKeditor->Value		= ($room) ? $room->getdescription():"";
		$oFCKeditor->Height		= 300;
		$oFCKeditor->Create() ;
		?>
	</div>
	
	<?php // facility list for hotel ?>
	<?php
		echo "<div class='row_field'>";
		echo "<table>";
		$facilities = Facility::getAllFacilities('ROOM');
		$hotel_facility_ids = array();
		if (isset($room_id)) {
			$room_facilities = RoomFacility::getAllFacilitiesForRoom($room_id);
			foreach ($room_facilities as $facility)
				$room_facility_ids[] = $facility->getid();
		}
		foreach ($facilities as $category => $facility_list) {
			echo "<tr class='tr_border'>";
			echo "<td align='right' valign='top'><div style='padding:10px'><b>".$category."</b></div></td>";
			echo "<td align='left'>";
			foreach ($facility_list as $facility) {
				echo "<div style='display:inline-block;float:left;padding:5px;width:210px;'>";
				echo "<input type='checkbox' id='facility_".$facility->getid()."' name='facility_".$facility->getid()."'";
				if (!empty($room_facility_ids) && in_array($facility->getid(), $room_facility_ids))
					echo "checked='checked'";
				echo " />";
				echo "<label for='facility_".$facility->getid()."'>".$facility->getdescription()."</lable>";
				echo "</div>";
			}

			echo "<div style='clear:both'></div>";
			echo "</td>";
			echo "</tr>";
		}
		echo "</table>";
		echo "</div>";
	
	?>
    
	<div class='row_field'><p>(*) Thông tin bắt buộc</p></div>
	<div class='row_field'>
    	<input type='reset' value='Reset' class='button' />
		<input type="submit" value="Save" class='button' />
	</div>
	
</form>
<script type="text/javascript">
	function validate_values() {
		name = $('#room_name').val();
		price = $('#price').val();
		
		message = "Các mục sau đây là bắt buộc hoặc sai giá trị: \n";
		ok = true;
		if (name == "") {
			message += "Tên Phòng \n";
			ok = false;
		}
		
		if (price == "") {
			message += "Giá Phòng \n";
			ok = false;
		}
		if (!ok) alert(message);
		return ok;
	}
</script>

<style>
	.tr_border td
	{
		border:1px solid #ccc;
	}
</style>